package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleConfigService;
import com.heima.common.constants.WmNewsMessageConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Component
public class ArticleIsDownListener {

    @Autowired
    private ApArticleConfigService apArticleConfigService;
//自媒体端WmNewsServiceImpl里的downOrUp发消息通知文章端上下架文章

    /**
     * 消费文章上下架消息
     * @param message
     */
    @KafkaListener(topics = WmNewsMessageConstants.WM_NEWS_UP_OR_DOWN_TOPIC)
    public void onMessage(String message){
        //article端接收到文章上下架消息
        //map转成json，article端接收到之后再转回map
        Map map = JSON.parseObject(message, Map.class);
        log.info("ArticleIsDownListener--->接收到文章上下架消息，message:{},map:{}",message,map);
        apArticleConfigService.updateByMap(map);
    }
}
